/*
 *  Confidential and Proprietary                                                                
 Copyright 2008 By                                                                                     
 SGAI & Hewlett-Packard Development Company, L.P. 	              
 All Rights Reserved                                                                                  

 Project Name : SGAI  MES                                                                                                                                       
 Class Name   : L4MessageHeader.java    
 Package      : com.hp.message.vo     
 */
package com.erdos.message.vo;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * ---------------------------------------------------------------------------------
 * this is a message header definition for L4.                                               
 @author sunf
 @since  2008-8-28 
 */
public class L4MessageHeader implements Serializable {
	private static final long serialVersionUID = -8112119645954228218L;
	/**
	 * assigned message type id.
	 */
	private  String messageTypeId;
	/**
	 * message id of this message
	 */
	private String messageId;
	/**
	 * saves the source message type id when reply to a request
	 */
	private String correlationMessageTypeId;

	/**
	 * correlated message id, it indicates the source message id to be replied to.
	 */
	private String correlationMessageId;	

	/**
	 * message send date.<br>
	 * format: YYYYMMDD
	 */
	private String sendDate;
	/**
	 * message send time.<br>
	 * format: HH24MISS
	 */
	private String sendTime;
	/**
	 * who sends this message
	 */
	private String sender;
	/**
	 * who is expected to receive this message
	 */
	private String receiver;
	
	/**
	 * the length of the message body and message header.
	 */
	private Integer length=-1;
	/**
	 * @return the messageTypeId
	 */
	public String getMessageTypeId() {
		return messageTypeId;
	}
	/**
	 * @param messageTypeId the messageTypeId to set
	 */
	public void setMessageTypeId(String messageTypeId) {
		this.messageTypeId = messageTypeId;
	}
	/**
	 * @return the messageId
	 */
	public String getMessageId() {
		return messageId;
	}
	/**
	 * @param messageId the messageId to set
	 */
	public void setMessageId(String messageId) {
		this.messageId = messageId;
	}
	/**
	 * @return the correlationMessageTypeId
	 */
	public String getCorrelationMessageTypeId() {
		return correlationMessageTypeId;
	}
	/**
	 * @param correlationMessageTypeId the correlationMessageTypeId to set
	 */
	public void setCorrelationMessageTypeId(String correlationMessageTypeId) {
		this.correlationMessageTypeId = correlationMessageTypeId;
	}
	/**
	 * @return the correlationMessageId
	 */
	public String getCorrelationMessageId() {
		return correlationMessageId;
	}
	/**
	 * @param correlationMessageId the correlationMessageId to set
	 */
	public void setCorrelationMessageId(String correlationMessageId) {
		this.correlationMessageId = correlationMessageId;
	}
	/**
	 * @return the sendDate
	 */
	public String getSendDate() {
		return sendDate;
	}
	/**
	 * @param sendDate the sendDate to set
	 */
	public void setSendDate(String sendDate) {
		this.sendDate = sendDate;
	}
	/**
	 * @return the sendTime
	 */
	public String getSendTime() {
		return sendTime;
	}
	/**
	 * @param sendTime the sendTime to set
	 */
	public void setSendTime(String sendTime) {
		this.sendTime = sendTime;
	}
	/**
	 * @return the sender
	 */
	public String getSender() {
		return sender;
	}
	/**
	 * @param sender the sender to set
	 */
	public void setSender(String sender) {
		this.sender = sender;
	}
	/**
	 * @return the receiver
	 */
	public String getReceiver() {
		return receiver;
	}
	/**
	 * @param receiver the receiver to set
	 */
	public void setReceiver(String receiver) {
		this.receiver = receiver;
	}
	
	public Integer getLength() {
		return length;
	}
	public void setLength(Integer length) {
		this.length = length;
	}
	
	/**
	 * returns a Date indicates the send date and time.
	 * if send date is empty, returns current date; else if time is null, time will be reset to "000000".
	 * if date and time format is incorrect, returns null.
	 * @return a Date 
	 * @author sunf
	 * @since  2008-8-14
	 */
	public Date getSendDateTime() {		
		String date=this.getSendDate();		
		String time=this.getSendTime();
		if(date==null || date.trim().length()==0) {			
			return new Date();
		} else {
			if(time==null || time.trim().length()==0) {
				time="000000";
			}
		}
		
		DateFormat formatter = new SimpleDateFormat(L2Messaging.DATE_PATTERN);
		
		return formatter.parse(date + time, new ParsePosition(0));
	}
	
	public String toString() {
		return new ToStringBuilder(this).append(this.messageTypeId).append(this.messageId)
			.append(this.correlationMessageTypeId).append(this.correlationMessageId)
			.append(this.sender).append(this.receiver).append(this.sendDate).append(this.sendTime)
			.toString();
	}
	
}
